package com.superman.supermarket.client.activity;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.Window;
import com.google.inject.Inject;
import com.superman.mvpframe.client.ajax.PostManAsyncCallBack;
import com.superman.mvpframe.client.event.ReloadEvent;
import com.superman.mvpframe.client.mvp.IPageView;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.supermarket.client.mvp.ShopAbstractActivity;
import com.superman.supermarket.client.view.refundprocess.RefundProcessView;

/**
 * 退款流程
 * 
 * @author superman
 * @version 2018年8月20日下午11:38:13
 */
public class RefundProcessActivity extends ShopAbstractActivity {

	private String refundId;

	@Inject
	RefundProcessView refundProcessView;

	private void getRefundProcess() {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("REFUND_ID", refundId);
		postman.post("refund/process", map, new PostManAsyncCallBack() {

			@Override
			public void onBusinessError(String statusCode) {

			}

			@Override
			public void onBusinessOK(String response) {
				parseRefundProcess(XJsonUtil.getBody(response));
			}
		});

	}

	@Override
	public IPageView getView() {
		return refundProcessView;
	}

	@Override
	public IPageViewPresenter getViewPresenter() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onActivity(EventBus eventBus) {

		eventBus.addHandler(ReloadEvent.TYPE, new ReloadEvent.ReloadEventHandler() {

			@Override
			public void reload(ReloadEvent event) {
				getRefundProcess();
			}
		});

	}

	private void parseRefundProcess(Map<String, Object> map) {
		map.put("REFUND_ID", refundId);
		refundProcessView.setRefundProcess(map);
	}

	@Override
	public void popToRefresh() {
		// TODO Auto-generated method stub

	}

	@Override
	public void popToRefresh(Object contextData) {
		Map map = (Map) contextData;
		if (map.containsKey("REFUND_ID"))
			getRefundProcess();

	}

	@Override
	public void pushToRefresh() {
		this.refundId = Window.Location.getParameter("refundid");
		getRefundProcess();
	}

}
